package mysql

import "gorm.io/gorm"

type UserWeek3 struct {
	gorm.Model
	Username string `gorm:"type:varchar(20);unique;comment:账户;"`
	Password string `gorm:"type:char(32);comment:密码;"`
	Mobile   string `gorm:"type:char(18);comment:手机号;"`
	Avatar   string `gorm:"type:varchar(255);comment:头像;"`
}

// 用户登录 用户名密码
func (u *UserWeek3) FindUsername(username, password string) error {
	return DB.Where("username = ?", username).Where("password = ?", password).Find(&u).Error
}

// 修改用户头像 手机验证码
func (u *UserWeek3) UpdateAvatarByMobile(mobile, avatar string) error {
	return DB.Model(&u).Where("mobile = ?", mobile).Update("avatar", avatar).Error
}

// 用户By手机号查询信息
func (u *UserWeek3) UserByMobileInfo(mobile string) error {
	return DB.Where("mobile = ?", mobile).Find(&u).Error
}

// 用户By用户名查询信息
func (u *UserWeek3) UserByUsernameInfo(username string) error {
	return DB.Where("username = ?", username).Find(&u).Error
}
